package com.smmisia.common.utils;


import org.springframework.stereotype.Component;

import java.util.Random;
/**
 * @author smmisia
 * @description: 生成随机用户名
 * @date 2024/12/26 10:59
 */
@Component
public class GenerateRandomUserName {

    private static final String PREFIX = "用户_";

    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    private static Random random = new Random();

    public static String generateRandomName() {
        StringBuilder sb = new StringBuilder();

        // 固定前缀 "用户_"
        sb.append(PREFIX);

        // 生成随机后缀，长度为8
        for (int i = 0; i < 8; i++) {
            int index = random.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(index));
        }

        return sb.toString();
    }
}
